<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>所有商户信息</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <style type="text/css">
        #mol {
            width: 120%;
        }
        .k{
            border: 1px solid #f0f0f0;
            text-align: center;
            display: inline-block;
            width: 200px ;
            margin-right: 30px;
            height: 20px;
        }
        .zi{
            font-weight: bold;
            display: inline-block;
            width: 100px ;
            text-align: right;
        }
        .one{
            margin-left: 30px;
            margin-top: 10px;
        }
        .two{
            margin-left: 30px;
            margin-top: 50px;
        }
        .three{
            margin-left: 30px;
            margin-top: 50px;
        }
        .bi{
            margin-top: 50px;
            margin-bottom: 10px;
        }
        #bi{
            text-align: center;
        }
        .tou{
            text-align: center;
            font-weight: bold;
        }
        .di{
            width: 534px;
            text-align: left;
        }
    </style>
</head>
<body>
<section>
    <form id="delete-form">
        <table class="table table-striped table-bordered table-condensed table-hover">
            <tr>
                <th>
                    <label>
                        <input type="checkbox"/>
                    </label>
                </th>
                <th>商户编号</th>
                <th>工单编号</th>
                <th>商户状态</th>
                <th>商户名称</th>
                <th>法人姓名</th>
                <th>法人身份证号</th>
                <th>装机地址</th>
                <th>结算人姓名</th>
                <th>结算人身份证号</th>
                <th>结算银行</th>
                <th>卡号</th>
                <th>备注</th>
                <th>审核状态</th>
                <th>创建时间</th>
                <th>审核时间</th>
                <th>报备</th>
                <th>详细信息</th>
            </tr>
            <tbody id="user-tbody"></tbody>
        </table>
    </form>
</section>

<form id="main-form" class="form-inline form-horizontal">
    <div class="modal fade he" id="insert-modal">
        <div class="modal-dialog">
            <div class="modal-content" id="mol">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title tou">详细信息</h4>
                </div>
                <div class="one">
                    <div class="zi">工单编号：</div><div id="workId" class="k"></div>
                </div>
                <div class="one">
                    <div class="zi">商户编号：</div><div id="merchantId" class="k"></div>
                    <div class="zi">商户名称：</div><div id="merchantName" class="k"></div>
                </div>
                <div class="one">
                    <div class="zi">法人姓名：</div><div id="legalName" class="k"></div>
                    <div class="zi">法人身份证：</div><div id="legalId" class="k"></div>
                </div>
                <div class="one">
                    <div class="zi">装机地址：</div><div id="install" class="k di"></div>
                </div>
                <div class="two">
                    <div class="zi">结算人姓名：</div><div id="settleName" class="k"></div>
                    <div class="zi">结算人身份证：</div><div id="settleId" class="k"></div>
                </div>
                <div class="one">
                    <div class="zi">行别：</div><div id="settleBankName" class="k"></div>
                    <div class="zi">卡号：</div><div id="cardId" class="k"></div>
                </div>
                <div class="one">
                    <div class="zi">结算类型：</div><div id="settleType" class="k"></div>
                    <div class="zi">备注：</div><div id="node" class="k"></div>
                </div>
                <div class="three">
                    <div class="zi">提交日期：</div><div id="createTime" class="k"></div>
                    <div class="zi">审核状态：</div><div id="workState" class="k"></div>
                </div>
                <div class="one">
                    <div class="zi">审核日期：</div><div id="checkTime" class="k"></div>
                </div>
                <div id="bi">
                    <button type="button" class="btn btn-info bi" data-dismiss="modal">关闭</button>
                </div>
            </div>
        </div>
    </div>
</form>

<script src="jquery360/jquery3.6.0.js"></script>
<script src="js/bootstrap.min.js"></script>
<script type="application/javascript">
    $(() => {
        $.ajax({
            "url": "/user/select-all",
            "type": "post",
            "dataType": "json",
            "async": false,
            "success": resp => {
                let userTbody = $("#user-tbody");
                $.each(resp["data"], (i, v) => {
                    let tr = $("<tr></tr>").appendTo(userTbody);
                    $(`<td><input type="hidden" name="id" value="${v["id"]}"/>${i + 1}</td>`).appendTo(tr);
                    if (v["merchantNum"] === undefined) {
                        $(`<td>无</td>`).appendTo(tr);
                    } else {
                        $(`<td>${v["merchantNum"]}</td>`).appendTo(tr);
                    }
                    $(`<td>${v["workOrderNum"]}</td>`).appendTo(tr);
                    if (v["merchantState"] === 0) {
                        $(`<td>正常</td>`).appendTo(tr);
                    } else {
                        $(`<td>注销</td>`).appendTo(tr);
                    }
                    $(`<td>${v["merchantName"]}</td>`).appendTo(tr);
                    $(`<td>${v["legalPersonName"]}</td>`).appendTo(tr);
                    $(`<td>${v["legalPersonIdMask"]}</td>`).appendTo(tr);
                    if (v["installedAddressP"] === 1) {
                        if (v["installedAddressC"] === 1001) {
                            if (v["installedAddressA"] === 1101) {
                                $(`<td>北京省北京市东城区${v["installedAddressDetail"]}</td>`).appendTo(tr);
                            } else if (v["installedAddressA"] === 1102) {
                                $(`<td>北京省北京市西城区${v["installedAddressDetail"]}</td>`).appendTo(tr);
                            }
                        }
                    } else if (v["installedAddressP"] === 2) {
                        if (v["installedAddressC"] === 2001) {
                            if (v["installedAddressA"] === 2101) {
                                $(`<td>河北省石家庄市长安区${v["installedAddressDetail"]}</td>`).appendTo(tr);
                            } else if (v["installedAddressA"] === 2102) {
                                $(`<td>河北省石家庄市桥西区${v["installedAddressDetail"]}</td>`).appendTo(tr);
                            }
                        } else if (v["installedAddressC"] === 2002) {
                            if (v["installedAddressA"] === 2201) {
                                $(`<td>河北省廊坊市固安县${v["installedAddressDetail"]}</td>`).appendTo(tr);
                            } else if (v["installedAddressA"] === 2202) {
                                $(`<td>河北省廊坊市广阳区${v["installedAddressDetail"]}</td>`).appendTo(tr);
                            }
                        }
                    } else if (v["installedAddressP"] === 3) {
                        if (v["installedAddressC"] === 3001) {
                            if (v["installedAddressA"] === 3101) {
                                $(`<td>山东省济南市天桥区${v["installedAddressDetail"]}</td>`).appendTo(tr);
                            } else if (v["installedAddressA"] === 3102) {
                                $(`<td>山东省济南市市中区${v["installedAddressDetail"]}</td>`).appendTo(tr);
                            }
                        } else if (v["installedAddressC"] === 3002) {
                            if (v["installedAddressA"] === 3201) {
                                $(`<td>山东省青岛市市南区${v["installedAddressDetail"]}</td>`).appendTo(tr);
                            } else if (v["installedAddressA"] === 3202) {
                                $(`<td>山东省青岛市市北区${v["installedAddressDetail"]}</td>`).appendTo(tr);
                            }
                        }
                    }
                    $(`<td>${v["settlementName"]}</td>`).appendTo(tr);
                    $(`<td>${v["settlementIdMask"]}</td>`).appendTo(tr);
                    $(`<td>${v["settlementBankName"]}</td>`).appendTo(tr);
                    $(`<td>${v["cardNummask"]}</td>`).appendTo(tr);
                    $(`<td>${v["note"]}</td>`).appendTo(tr);
                    if (v["workOrderCheckState"] === 1) {
                        $(`<td>待审核</td>`).appendTo(tr);
                    } else if (v["workOrderCheckState"] === 2) {
                        $(`<td>审核通过</td>`).appendTo(tr);
                    } else {
                        $(`<td>审核未通过</td>`).appendTo(tr);
                    }
                    if (v["createTime"] !== null) {
                        $(`<td>${timeStamp2String(Date.parse(v["createTime"]))}</td>`).appendTo(tr);
                    } else {
                        $(`<td>${v["createTime"]}</td>`).appendTo(tr);
                    }
                    if (v["checkTime"] !== null) {
                        $(`<td>${timeStamp2String(Date.parse(v["checkTime"]))}</td>`).appendTo(tr);
                    } else {
                        $(`<td>${v["checkTime"]}</td>`).appendTo(tr);
                    }
                    let operaTd = $(`<td></td>`).appendTo(tr);
                    let updateA = $(`<a href="javascript:;">报备</a>`).appendTo(operaTd);
                    updateA.click(() => {
                        alert("报备成功！");
                    });
                    // sessionStorage.setItem("workOrderNum", v["workOrderNum"]);
                    let info = $(`<td></td>`).appendTo(tr);
                    let infoId = $(`<a href="javascript:;">详细信息</a>`).appendTo(info);
                    infoId.click(() => {
                        // let workOrderNum = sessionStorage.getItem("workOrderNum");
                        $.ajax({
                            "url": "/user/select-one-all",
                            "type": "post",
                            "data": "workOrderNum=" + v["workOrderNum"],
                            "dataType": "json",
                            "success": resp => {
                                if (resp["code"] === 1){
                                    $("#workId").text(resp["data"]["workOrderNum"]);
                                    $("#merchantId").text("");
                                    $("#merchantId").text(resp["data"]["merchantNum"]);
                                    $("#merchantName").text(resp["data"]["merchantName"]);
                                    $("#legalName").text(resp["data"]["legalPersonName"]);
                                    $("#legalId").text(resp["data"]["legalPersonIdMask"]);
                                    if (resp["data"]["installedAddressP"] === 1) {
                                        if (resp["data"]["installedAddressC"] === 1001) {
                                            if (resp["data"]["installedAddressA"] === 1101) {
                                                $("#install").html(`北京省北京市东城区${resp["data"]["installedAddressDetail"]}`);
                                            } else if (resp["data"]["installedAddressA"] === 1102) {
                                                $("#install").html(`北京省北京市西城区${resp["data"]["installedAddressDetail"]}`);
                                            }
                                        }
                                    } else if (resp["data"]["installedAddressP"] === 2) {
                                        if (resp["data"]["installedAddressC"] === 2001) {
                                            if (resp["data"]["installedAddressA"] === 2101) {
                                                $("#install").html(`河北省石家庄市长安区${resp["data"]["installedAddressDetail"]}`);
                                            } else if (resp["data"]["installedAddressA"] === 2102) {
                                                $("#install").html(`河北省石家庄市桥西区${resp["data"]["installedAddressDetail"]}`);
                                            }
                                        } else if (resp["data"]["installedAddressC"] === 2002) {
                                            if (resp["data"]["installedAddressA"] === 2201) {
                                                $("#install").html(`河北省廊坊市固安县${resp["data"]["installedAddressDetail"]}`);
                                            } else if (resp["data"]["installedAddressA"] === 2202) {
                                                $("#install").html(`河北省廊坊市广阳区${resp["data"]["installedAddressDetail"]}`);
                                            }
                                        }
                                    } else if (resp["data"]["installedAddressP"] === 3) {
                                        if (resp["data"]["installedAddressC"] === 3001) {
                                            if (resp["data"]["installedAddressA"] === 3101) {
                                                $("#install").html(`山东省济南市天桥区${resp["data"]["installedAddressDetail"]}`);
                                            } else if (resp["data"]["installedAddressA"] === 3102) {
                                                $("#install").html(`山东省济南市市中区${resp["data"]["installedAddressDetail"]}`);
                                            }
                                        } else if (resp["data"]["installedAddressC"] === 3002) {
                                            if (resp["data"]["installedAddressA"] === 3201) {
                                                $("#install").html(`山东省青岛市市南区${resp["data"]["installedAddressDetail"]}`);
                                            } else if (resp["data"]["installedAddressA"] === 3202) {
                                                $("#install").html(`山东省青岛市市北区${resp["data"]["installedAddressDetail"]}`);
                                            }
                                        }
                                    }
                                    $("#settleName").text(resp["data"]["settlementName"]);
                                    $("#settleId").text(resp["data"]["settlementIdMask"]);
                                    $("#settleBankName").text(resp["data"]["settlementBankName"]);
                                    $("#cardId").text(resp["data"]["cardNummask"]);
                                    $("#settleType").text("T+N");
                                    $("#note").text(resp["data"]["note"]);
                                    $("#createTime").text(resp["data"]["createDate"]);
                                    if (resp["data"]["workOrderCheckState"] === 1) {
                                        $("#workState").text("待审核");
                                    } else if (resp["data"]["workOrderCheckState"] === 2) {
                                        $("#workState").text("审核通过");
                                    } else {
                                        $("#workState").text("审核未通过");
                                    }
                                    $("#checkTime").text(resp["data"]["checkDate"]);
                                    $("#insert-modal").modal();
                                }
                            }
                        });
                    });
                });
            }
        });

        function timeStamp2String(time) {
            let datetime = new Date();
            datetime.setTime(time);
            let year = datetime.getFullYear();
            let month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
            let date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
            let hour = datetime.getHours() < 10 ? "0" + datetime.getHours() : datetime.getHours();
            let minute = datetime.getMinutes() < 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
            let second = datetime.getSeconds() < 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
            return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
        }
    });
</script>
</body>
</html>